package com.example.demo;

import com.example.demo.model.Emp;
import lombok.extern.slf4j.Slf4j;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@Slf4j
public class DemoApplication implements CommandLineRunner {

	@Autowired
	EmpRepository empRepository;

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

	@Override
	public void run(String... args) throws Exception {
		log.info("out");
		Emp emp = Emp.builder().name("张三").job("主管")
				.salary(Money.of(CurrencyUnit.of("CNY"), 20.0)).build();
		empRepository.save(emp);
		log.info("count {}",empRepository.count());
		empRepository.editEmp("李四",1L);
		empRepository.findAll().forEach(e->log.info(e.toString()));
		//log.info(empRepository.findById(1L).toString());
		log.info("like {}",empRepository.findEmpsByNameLike("李%"));
		log.info("$$$ {}",
                empRepository.findEmpsByNameEqualsAndJobEqualsAndSalaryEquals("李四","主管",
                        Money.of(CurrencyUnit.of("CNY"), 20.0)));
		log.info("*** {}",
                empRepository.findEmps("李四","主管",
                        Money.of(CurrencyUnit.of("CNY"), 20.0)));
		log.info("@@@ {}",
                empRepository.findEmployees("李四","主管",
                        Money.of(CurrencyUnit.of("CNY"), 20.0)));
	}



}
